package com.yybray;

import java.util.function.Function;

/**
 * Created by Bray on 2017/6/5.
 */
public class ExecuteTest {

    public static long execute(Function<Long, Long> adder, long n) {
        long fastest = Long.MAX_VALUE;
        for (int i = 0; i < 10; i++) {
            //纳秒
            long start = System.nanoTime();
            long sum = adder.apply(n);
            long duration = (System.nanoTime() - start) / 1_000_000;
            //System.out.println("Result: " + sum);
            System.out.print(duration + ", ");
            //取最快运行时间
            if (duration < fastest) fastest = duration;
        }
        System.out.println();
        return fastest;
    }

}
